<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>案例4</title>
    <style>
        input {
            width: 30px;
        }
    </style>
</head>

<body>
    <div style="width: 200px;margin: 0 auto;">
        <input type="text" id="n1"> VS <input id="n2" type="text">
        <button onclick="getmax()">最大值</button>
        <span id="sum1">?</span>
    </div>

    <script>
        let n1 = document.querySelector('#n1')
        let n2 = document.querySelector('#n2')
        let sum1 = document.querySelector('#sum1')

        n1.oninput = function() {
            if (isNaN(this.value)) {
                this.value = ""
            }
        }
        n2.oninput = function() {
            if (isNaN(this.value)) {
                this.value = ""
            }
        }

        function getmax() {
            let temp = parseInt(n1.value) > parseInt(n2.value) ? parseInt(n1.value) : parseInt(n2.value)
            sum1.innerText = temp
        }
    </script>
</body>

</html>